<template>
  <div class="app-container">
    <el-form :model="queryParams"  class="top" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="类型" prop="sceneryType">
        <el-select v-model="queryParams.sceneryType" placeholder="请选择类型" clearable>
          <el-option
            v-for="dict in dict.type.scenery_data_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="名称" prop="sceneryName">
        <el-input
          v-model="queryParams.sceneryName"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人均价格" prop="sceneryPrice">
        <el-input
          v-model="queryParams.sceneryPrice"
          placeholder="请输入人均价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评分" prop="sceneryScore">
        <el-select v-model="queryParams.sceneryScore" placeholder="请选择评分" clearable>
          <el-option
            v-for="dict in dict.type.scenery_score"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="简介" prop="sceneryInfo">
        <el-input
          v-model="queryParams.sceneryInfo"
          placeholder="请输入简介"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排队时间" prop="sceneryWaitTime">
        <el-input
          v-model="queryParams.sceneryWaitTime"
          placeholder="请输入排队时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['scenery:data:add']"
        >新增</el-button>
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['scenery:data:edit']"-->
<!--        >修改</el-button>-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['scenery:data:remove']"-->
<!--        >删除</el-button>-->
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['scenery:data:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>
    <el-col :span="6" class="card-box" v-for="item in this.dataList" :class="isFlipped ? 'flipped' : ''">
      <transition name="flip">
        <el-card class="card-front" v-if="!isFlipped" key="front" :style="{backgroundImage: 'url(' + item.sceneryPhoto + ')'}">
          <div class="card-header">
            <div class="card-name">
              <span class="card-ID">ID:</span>{{item.sceneryId}}
              <span class="card-type">{{dict.type.scenery_data_type[item.sceneryType].label }}</span>
            </div>
            <h3 class="card-title">{{item.sceneryName}}</h3>
          </div>
          <div class="card-middle">
            <div class="card-middle1">
              <img class="card-symbol" src="./money1.png">
              <span class="card-count">{{item.sceneryPrice}}</span>
            </div>
            <div class="card-middle2">
              <img class="card-symbol" src="./time1.png">
              <span class="card-count">{{item.sceneryWaitTime}}</span>
              <span class="card-symbol">min</span>
            </div>
          </div>
          <div class="card-bottom">
            <img class="card-symbol" src="./star11.png" v-for="item in (5-item.sceneryScore)">
          </div>
          <div>
            <el-button
              class="card-button-edit"
              size="mini"
              @click="handleUpdate(item)"
              v-hasPermi="['scenery:data:edit']"
            >修改</el-button>
            <el-button
              class="card-button-delete"
              size="mini"
              @click="handleDelete(item)"
              v-hasPermi="['scenery:data:remove']"
            >删除</el-button>
            <el-button
              class="card-button-flip"
              size="mini"
              @click="flipCard"
            >简介</el-button>
            <div class="card-label">
              <span class="card-text">{{dict.type.scenery_label[item.sceneryLabel].label}}</span>
            </div>
          </div>
        </el-card>
        <el-card class="card-back" v-else key="back" :style="{backgroundImage: 'url(' + item.sceneryPhoto + ')'}">
          <p class="card-info">{{item.sceneryInfo}}</p>
          <div>
            <el-button
              class="card-button-flip"
              size="mini"
              @click="flipCard"
            >返回</el-button>
          </div>
        </el-card>
      </transition>
    </el-col>
    <!--    为了让分页的那个条下去，不要错位-->
    <div style="clear: both;"></div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
<!--    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">-->
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="id" align="center" prop="sceneryId" />-->
<!--      <el-table-column label="类型" align="center" prop="sceneryType">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.scenery_data_type" :value="scope.row.sceneryType"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="名称" align="center" prop="sceneryName" />-->
<!--      <el-table-column label="照片" align="center" prop="sceneryPhoto" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <image-preview :src="scope.row.sceneryPhoto" :width="50" :height="50"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="人均价格" align="center" prop="sceneryPrice" />-->
<!--      <el-table-column label="评分" align="center" prop="sceneryScore">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.scenery_score" :value="scope.row.sceneryScore"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="标签" align="center" prop="sceneryLabel">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.scenery_label" :value="scope.row.sceneryLabel ? scope.row.sceneryLabel.split(',') : []"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="简介" align="center" prop="sceneryInfo" />-->
<!--      <el-table-column label="排队时间" align="center" prop="sceneryWaitTime" />-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['scenery:data:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['scenery:data:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--    </el-table>-->
    <!-- 添加或修改景点信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="类型" prop="sceneryType">
          <el-select v-model="form.sceneryType" placeholder="请选择类型">
            <el-option
              v-for="dict in dict.type.scenery_data_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="名称" prop="sceneryName">
          <el-input v-model="form.sceneryName" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="照片" prop="sceneryPhoto">
          <image-upload v-model="form.sceneryPhoto"/>
        </el-form-item>
        <el-form-item label="人均价格" prop="sceneryPrice">
          <el-input v-model="form.sceneryPrice" placeholder="请输入人均价格" />
        </el-form-item>
        <el-form-item label="评分" prop="sceneryScore">
          <el-select v-model="form.sceneryScore" placeholder="请选择评分">
            <el-option
              v-for="dict in dict.type.scenery_score"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签" prop="sceneryLabel">
          <el-checkbox-group v-model="form.sceneryLabel">
            <el-checkbox
              v-for="dict in dict.type.scenery_label"
              :key="dict.value"
              :label="dict.value">
              {{dict.label}}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="简介" prop="sceneryInfo">
          <el-input v-model="form.sceneryInfo" placeholder="请输入简介" />
        </el-form-item>
        <el-form-item label="排队时间" prop="sceneryWaitTime">
          <el-input v-model="form.sceneryWaitTime" placeholder="请输入排队时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { listData, getData, delData, addData, updateData } from "@/api/scenery/data";
import dict from "@/utils/dict";
import {background} from "quill/ui/icons";

export default {
  name: "Data",
  dicts: ['scenery_label', 'scenery_score', 'scenery_data_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 景点信息管理表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否翻转
      isFlipped: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        sceneryType: null,
        sceneryName: null,
        sceneryPrice: null,
        sceneryScore: null,
        sceneryLabel: null,
        sceneryInfo: null,
        sceneryWaitTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sceneryType: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
        sceneryName: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    background,
    dict,
    /** 查询景点信息管理列表 */
    getList() {
      this.loading = true;
      listData(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sceneryId: null,
        sceneryType: null,
        sceneryName: null,
        sceneryPhoto: null,
        sceneryPrice: null,
        sceneryScore: null,
        sceneryLabel: [],
        sceneryInfo: null,
        sceneryWaitTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sceneryId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加景点信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sceneryId = row.sceneryId || this.ids
      getData(sceneryId).then(response => {
        this.form = response.data;
        this.form.sceneryLabel = this.form.sceneryLabel.split(",");
        this.open = true;
        this.title = "修改景点信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.sceneryLabel = this.form.sceneryLabel.join(",");
          if (this.form.sceneryId != null) {
            updateData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sceneryIds = row.sceneryId || this.ids;
      this.$modal.confirm('是否确认删除景点信息管理编号为"' + sceneryIds + '"的数据项？').then(function () {
        return delData(sceneryIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('scenery/data/export', {
        ...this.queryParams
      }, `data_${new Date().getTime()}.xlsx`)
    },
    /** 翻转卡片操作 */
    flipCard() {
      this.isFlipped = !this.isFlipped;
    }
  }
};
</script>
